/*
 * File:   Rana.h
 * Author: jcrada
 *
 * Created on 28 April 2011, 2:25 PM
 */

#ifndef ECB_RANA_H
#define	ECB_RANA_H

#include "ecb/base/Problem.h"
#include <cmath>
namespace ecb {

    /* Source:
     * @incollection{springer-dif.evo,
        Author = {Price, Kenneth and Storn, Rainer M. and Lampinen, Jouni A.},
        title={{Appendix}},
        booktitle = {Differential Evolution: A Practical Approach to Global Optimization},
        series={Natural Computing Series},
        editor={Rozenberg, G. and Bäck, Th. and Eiben, A. E. and Kok, J. N. and Spaink, H. P.},
        publisher = {Springer-Verlag Berlin Heidelberg},
        pages = {513-533},
        year = {2005}
        }
     */
    class Rana : public Problem {
    public:

        Rana(const std::string& id = "Rana", const std::string& name = "Rana",
                int dimensions = 0, scalar minimum = -512, scalar maximum = 512,
                bool minimization = true) :
        Problem(id, name, dimensions, minimum, maximum, minimization) {
        }

        scalar f(const std::vector<scalar>& x) {
            scalar result = 0, alpha, beta;
            for (size_t i = 0; i < x.size() - 1; ++i) {
                alpha = std::sqrt(std::fabs(x[i + 1] + 1 - x[i]));
                beta = std::sqrt(std::fabs(x[i + 1] + 1 + x[i]));
                result += x[i] * std::sin(alpha) * std::cos(beta) + x[i + 1] * std::cos(alpha) * std::sin(beta);
            }
            return result;
        }
    };
}

#endif	/* ECB_RANA_H */

